﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Dazaza.Repositories;
using Dazaza.Domain.Model.SearchInfo;

namespace Dazaza.UI.Mvc.Controllers
{
    public class TagController : BaseController
    {
        [OutputCache(Duration=1600)]
        public ActionResult Index(string tag, int? pageindex)
        {
            tag = tag ?? string.Empty;

            Models.TagIndexViewModel model = new Models.TagIndexViewModel(masterViewModel);

            model.MasterViewModel.HeaderInfo.PageTitle = "Tag " + tag;
            model.Tab = Models.Enums.EnumTab.None;

            // searchInfo
            InfoSearchInfo searchInfo = new InfoSearchInfo()
            {
                PageIndex = pageindex ?? 1,
                PageSize = this.masterViewModel.PagerInfo.PageSize,
                ListType = EnumInfoListType.All,
                Tag = tag
            };

            model.InfoModelList = InfoRepository.SearchByTag(searchInfo);

            model.Pager = new Models.PagerInfo()
            {
                PageIndex = searchInfo.PageIndex,
                RecordCount = searchInfo.RecordCount
            };
            model.Pager.LinkFormat = "/tag/{1}_p{0}";
            model.Pager.PrePageLinkParameters = new string[] { (model.Pager.PageIndex - 1).ToString(),tag };
            model.Pager.NextPageLinkParameters = new string[] { (model.Pager.PageIndex + 1).ToString(),tag };

            return View(model);
        }

    }
}
